<form lay-filter="storageWorkAddForm" id="storageWorkAddForm" class="layui-form open-form">
  <div class="open-model" id="storageWorkAddFormContent">
    <div class="open-auto">
      <input type="hidden" id="productDetailId" name="productDetailId" lay-verify="required" />
      <input type="hidden" name="productTypeId" />
      <input type="hidden" id="warehouseInventoryTypeId" name="warehouseInventoryTypeId" />
      <input type="hidden" id="supplierCode" name="supplierCode" />
      <input type="hidden" id="supplierName" name="supplierName" />
      <input type="hidden" id="supplierId" name="supplierId" />
      <input type="hidden" id="unitCode" name="unitCode" />
      <input type="hidden" id="unitId" name="unitId" />
      <input type="hidden" id="subUnitName" name="subUnitName" />
      <input type="hidden" id="skuCode" name="skuCode" />
      <input type="hidden" id="inTypeName" name="inTypeName" />
      <input type="hidden" id="inventoryTypeCode" name="inventoryTypeCode" />
      <div class="standardAdd">
        <div class="standardAddShow" style="">
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 100px">入库类型</label>
              <div class="layui-input-block" style="margin-left: 130px">
                <select id="inType" lay-filter="inType" name="inType" lay-search></select>
                <!-- <input type="text"  id="inTypeName" name="inTypeName" class="layui-input" lay-filter="inTypeName" lay-search /> -->
              </div>
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">入库签收单</label>
            <div class="layui-input-block" style="margin-left: 130px; display: flex; align-items: center">
              <!-- <select id="purchaseSignForId" name="purchaseSignForId" lay-filter="purchaseSignForId" lay-search lay-verify="required"></select> -->
              <input name="purchaseSignForId" id="purchaseSignForId" type="hidden" />
              <input class="layui-input" style="flex: 1" disabled id="signNo" name="signNo" />
              <button class="layui-btn layui-btn-xs" type="button" id="purchaseSignForCodeBox">选择签收单</button>
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">订单单号</label>
            <div class="layui-input-block" style="margin-left: 130px">
              <input class="layui-input" disabled id="externalCode" name="externalCode" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">签收任务编号</label>
            <div class="layui-input-block" style="margin-left: 130px">
              <input class="layui-input" disabled id="logisticsNo" name="logisticsNo" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">运单编号</label>
            <div class="layui-input-block" style="margin-left: 130px">
              <input class="layui-input" disabled id="waybillNo" name="waybillNo" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">供应商名称</label>
            <div class="layui-input-block" style="margin-left: 130px">
              <input class="layui-input" disabled id="supplierName" name="supplierName" />
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">供应商编码</label>
            <div class="layui-input-block" style="margin-left: 130px">
              <input class="layui-input" disabled id="supplierId" name="supplierId" />
            </div>
          </div>
        </div>
      </div>
      <div class="layui-col-xs3" id="skuInfo" style="display: none">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">入库类型</label>
          <div class="layui-input-block" style="margin-left: 130px">
            <select name="inType" lay-filter="inType" lay-search>
              <option value="9">盘点入库</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs3">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">签收入库产品</label>
          <div class="layui-input-block" style="margin-left: 130px">
            <div id="standardSku" style="display: flex; align-items: center">
              <select id="purchaseSignForProductId" name="purchaseSignForProductId" lay-filter="purchaseSignForProductId" lay-search></select>
            </div>
          </div>
        </div>
      </div>

      <div class="layui-col-xs3">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">物料名称</label>
          <div class="layui-input-block" style="margin-left: 130px">
            <input type="text" name="skuName" id="skuName" class="layui-input" disabled />
          </div>
        </div>
      </div>
      <div class="layui-col-xs3">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">物料规格号</label>
          <div class="layui-input-block" style="margin-left: 130px">
            <input type="text" name="skuSpec" id="skuSpec" class="layui-input" disabled />
          </div>
        </div>
      </div>

      <div class="standardAdd">
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">待入库总数</label>
            <div class="layui-input-block" style="margin-left: 130px">
              <input type="text" name="restQuantity" id="restQuantity" class="layui-input" disabled />
            </div>
          </div>
        </div>
      </div>
      <div class="layui-col-xs3">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">入库仓库</label>
          <div class="layui-input-block" style="margin-left: 130px">
            <select id="warehouseId" name="warehouseId" lay-filter="warehouseId" lay-search lay-verify="required"></select>
            <input type="hidden" id="warehouseTypeId" name="warehouseTypeId" />
            <input type="hidden" id="workbinStatus" name="workbinStatus" />
          </div>
        </div>
      </div>
      <!-- <div class="layui-col-xs3">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">入库数量</label>
          <div class="layui-input-block" style="margin-left: 130px">
            <input type="number" name="quantity" class="layui-input" id="quantity" />
          </div>
        </div>
      </div> -->
      <!-- // 价格暂时隐藏 -->
      <!-- <div class="layui-col-xs3">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">单价</label>
          <div class="layui-input-block" style="margin-left: 130px">
            <input type="number" name="price" class="layui-input" id="price" step="0.000001" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs3">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">总价 </label>
          <div class="layui-input-block" style="margin-left: 130px">
            <input type="text" name="totalPrice" class="layui-input" id="totalPrice" disabled />
          </div>
        </div>
      </div> -->

      <div class="layui-form-item">
        <button class="layui-btn" id="addNewLocation" type="button">添加到新的库区库位</button>
        <table class="layui-table" id="locationTable" lay-filter="locationTable"></table>
      </div>
      <!-- <div class="layui-form-item text-right">
        <button class="layui-btn" lay-filter="purchaseStorageWorkFormAddSubmit" type="button" lay-submit>提交</button>
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div> -->
    </div>
  </div>
</form>

<script type="text/html" id="standardSkuTpl">
  <div class="layui-card">
    <div class="layui-card-body">
      <div class="layui-form" lay-filter="standardSkuForm">
        <div class="layui-form-item lay-query-content">
          <div class="lay-query-box">
            <div class="query-lt">
              <div class="layui-inline">
                <label class="layui-form-label w-auto">物料编号：</label>
                <div class="layui-input-inline">
                  <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号" lay-filter="skuCode" />
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label w-auto">物料名称：</label>
                <div class="layui-input-inline">
                  <input name="skuName" class="layui-input" type="text" placeholder="请输入物料名称" lay-filter="skuName" />
                </div>
              </div>
              <div class="layui-inline">
                <button type="button" class="layui-btn icon-btn color-green" lay-filter="searchStandardSku" lay-submit layui-form-keyDownSearch="true">查询</button>
                <button class="layui-btn icon-btn color-white" lay-filter="resetStandardSku" lay-submit>重置</button>
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item ">
          <button class="layui-btn " lay-filter="standardSkuFormAddSubmit" lay-submit>确认选择</button>
        </div>
      </div>
      <table class="layui-table" lay-filter="standardSkuTable" id="standardSkuTable"></table>
    </div>
  </div>
</script>
<script type="text/html" id="barDemo">
  <button class="layui-btn layui-btn-sm" lay-event="initStorageWork" type="button">入库作业</button>
</script>

<script type="text/html" id="storageWorkAddFormDivContent"></script>
<script>
  layui.use(["layer", "form", "table", "admin", "laytpl"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laytpl = layui.laytpl;
    const nowData = { ...parentData };

    if (nowData.eventName == "simpleAdd") {
      let addSkuIndex = null;
      $("#skuInfo").show();
      $(".standardAddShow").show();
      // 移除
      $(".standardAdd").html("");
      $("#standardSku").html(
        '<span id="standardSkuCode"></span><button style="margin-left: 15px;" class="layui-btn layui-btn-sm" type="button" id="standardSkuBtn">选择物料</button>'
      );
      $("#standardSkuBtn").click(function () {
        addSkuIndex = admin.formOpen({
          area: ["90%", "80%"],
          title: "选择物料",
          // content: $("#standardSkuTpl").html(),
          path: "components/purchase/skuTableForm.html",
          success: function () {
            parentData.type = "radio";
          },
          end: function () {
            if (!childData.list) {
              return;
            }
            let obj = childData.list[0];
            console.log(123, obj);

            $("#standardSkuCode").html(obj.skuCode);
            layer.msg("选择成功");
            form.val("storageWorkAddForm", {
              skuCode: obj.skuCode,
              skuName: obj.skuName,
              skuSpec: obj.skuSpec,
              productDetailId: obj.productDetailId,
              productTypeId: obj.productTypeId
            });
            setLocationTable();
          }
        });
      });
    }

    table.render({
      elem: "#locationTable",
      url: config.base + "enterprise/storage/admin/productInventoryDetail/list",
      where: {
        productDetailId: $("#productDetailId").val() ? $("#productDetailId").val() : "-1",
        warehouseId: $("#warehouseId") ? $("#warehouseId").val() : "-1"
      },
      data: [],
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          // {
          //   type: "radio",
          //   width: 50
          // },
          {
            type: "numbers",
            width: 50,
            title: "序号"
          },
          {
            // field: "warehouseAreaId",
            field: "warehouseAreaName",
            align: "center",
            title: "所属库区"
          },
          // {
          //   field: "warehouseShelfId",
          //   align: "center",
          //   title: "所属货架",
          //   templet: (d) => {
          //     if (d.tyep == "新增") {
          //       let options = d.warehouseShelfList.map((item) => {
          //         return {
          //           value: item.id,
          //           label: item.name
          //         };
          //       });

          //       return admin.setTableSelect("warehouseShelfId", options, false, "warehouseShelfId")(d);
          //     } else {
          //       return d.warehouseShelfName;
          //     }
          //   }
          // },
          {
            // field: "warehouseShelfSpaceId",
            field: "warehouseShelfSpaceCode",
            align: "center",
            title: "所在库位"
          },
          {
            // field: "palletBoxId",
            field: "palletBoxCode",
            align: "center",
            title: "料箱编号",
            templet: (d) => {
              if (d.palletBoxId == "0") {
                return "无料箱";
              } else {
                return d.palletBoxCode;
              }
            }
          },
          {
            field: "quantity",
            align: "center",
            title: "库存数量"
          },
          {
            field: "operate",
            align: "center",
            title: "操作",
            toolbar: "#barDemo"
          }
        ]
      ]
    });
    //<button class="layui-btn layui-btn-xs" type="button" id="purchaseSignForCodeBox">选择签收单</button>
    const openAddForm = (data) => {
      let warehouseId = form.val("storageWorkAddForm").warehouseId;
      let productDetailId = form.val("storageWorkAddForm").productDetailId;
      let warehouseInventoryTypeId = form.val("storageWorkAddForm").inType;

      if (warehouseId && productDetailId && warehouseInventoryTypeId) {
        admin.formOpen({
          area: ["60%", "80%"],
          title: "入库作业",
          path: "components/purchase/purchaseStorageWorkFormAdd.html",
          success: function () {
            console.log("parentData", parentData)
            parentData.data = { ...form.val("storageWorkAddForm"), ...data };
            parentData.eventName = nowData.eventName;
          },
          end: function () {
            // $()
            if (childData.status == "success") {
              let num = $("#restQuantity").val() - childData.quantity;
              $("#restQuantity").val(num);
            }
          }
        });
      } else {
        layer.msg("请选择入库类型、入库仓库、签收产品");
      }
    };
    $("#addNewLocation").click(function () {
      openAddForm();
    });
    table.on("tool(locationTable)", function (obj) {
      var data = obj.data;
      if (obj.event === "initStorageWork") {
        openAddForm({
          ...data,
          ...{
            // skuName: $("#skuName").val(),
            // skuCode: $("#skuCode").val(),
            // skuSpec: $("#skuSpec").val(),
            purchaseSignForId: $("#purchaseSignForId").val(),
          }
        });
        // if (data.warehouseAreaId && data.warehouseShelfSpaceId) {
        //   let warehouseAreaName = "";
        //   let warehouseShelfSpaceCode = "";
        //   if (data.warehouseAreaName) {
        //     warehouseAreaName = data.warehouseAreaName;
        //   } else {
        //     warehouseAreaName = data.warehouseAreaList.find((item) => item.id == data.warehouseAreaId).name;
        //   }
        //   if (data.warehouseShelfSpaceCode) {
        //     warehouseShelfSpaceCode = data.warehouseShelfSpaceCode;
        //   } else {
        //     warehouseShelfSpaceCode = data.warehouseShelfSpaceList.find((item) => item.id == data.warehouseShelfSpaceId).code;
        //   }
        //   let palletBoxName = data.palletBoxList ? data.palletBoxList.find((item) => item.id == data.palletBoxId).code : "";
        //   let obj = {
        //     $("#skuName").val(),
        //     skuCode: $("#skuCode").val(),
        //     skuSpec: $("#skuSpec").val(),
        //     productDetailId: $("#productDetailId").val(),
        //     productTypeId: $("#productTypeId").val(),
        //     warehouseInventoryTypeId: $("#warehouseInventoryTypeId").val(),
        //     warehouseAreaName,
        //     warehouseShelfSpaceCode,
        //     warehouseAreaId: data.warehouseAreaId,
        //     warehouseShelfId: data.warehouseShelfId,
        //     warehouseShelfSpaceId: data.warehouseShelfSpaceId,
        //     palletBoxId: data.palletBoxId ? data.palletBoxId : 0
        //   };
        //   console.log(obj);
        //   admin.formOpen({
        //     area: ["40%", "60%"],
        //     title: "入库作业",
        //     // content: $("#storageWorkAddFormDivContent").html(),
        //     path: "components/purchase/purchaseStorageWorkFormAdd.html",
        //     success: function () {
        //       // form.val("initWorkForm", obj);
        //       parentData.eventName = nowData.eventName;
        //       parentData.data = data;
        //     }
        //   });
        // } else {
        //   layer.msg("请选择入库库区和库位");
        // }
      }
    });
    await admin.initDataSelectPro(
      "enterprisecab/warehouse/admin/warehouseInventoryType/list",
      { limit: 999, inventoryType: "in", status: "enable" },
      "inType",
      "入库类型",
      (d, obj) => {
        console.log(obj);
         form.val("storageWorkAddForm", {
          logisticsNo: "",
          waybillNo: "",
          inTypeName: "",
          externalCode:"",
          supplierName: "",
          supplierCode: "",
          supplierId: "",
          purchaseSignForId: "",
          signNo:"",
          warehouseInventoryTypeId: "",
          restQuantity: "",
          quantity: "",
          skuSpec: "",
          skuName: "",
          skuCode: "",
          purchaseSignForProductId: "",
          warehouseId: "",
          workbinStatus: ""
        });
        // 重载表格并传入空数据
        setLocationTable();
        form.val("storageWorkAddForm", {
          inventoryTypeCode: obj.code
        });
      }
      // async (d, obj) => {
      //   //         //入库签收单列表
      //   $("#purchaseSignForId").empty();
      //   if (d.value) {
      //     form.val("storageWorkAddForm", {
      //       warehouseInventoryTypeId: d.value
      //     });
      //     await admin.initDataSelectPro(
      //       "enterprise/purchase/admin/purchaseSignFor/list",
      //       {
      //         limit: 999,
      //         status: "2",
      //         inventoryTypeCode: obj.code,
      //         workType: "doWork"
      //       },
      //       "purchaseSignForId",
      //       "入库签收单",
      //       (d, obj) => {
      //         form.val("storageWorkAddForm", {
      //           logisticsNo: "",
      //           waybillNo: "",
      //           inTypeName: "",
      //           externalCode: "",
      //           supplierName: "",
      //           supplierCode: ""
      //         });
      //         $("#purchaseSignForProductId").empty();
      //         if (d.value) {
      //           form.val("storageWorkAddForm", {
      //             logisticsNo: obj.logisticsNo,
      //             waybillNo: obj.waybillNo,
      //             inTypeName: obj.inventoryTypeName,
      //             externalCode: obj.sn,
      //             supplierName: obj.supplierName,
      //             supplierCode: obj.supplierCode,
      //             supplierId: obj.supplierId
      //           });
      //           admin.initDataSelectPro(
      //             "enterprise/purchase/admin/purchaseSignForProduct/list",
      //             {
      //               limit: 999,
      //               purchaseSignForId: d.value
      //             },
      //             "purchaseSignForProductId",
      //             "入库签收产品",
      //             async (d, obj) => {
      //               form.val("storageWorkAddForm", {
      //                 ...obj,
      //                 warehouseInventoryTypeId: "",
      //                 restQuantity: "",
      //                 quantity: "",
      //                 skuSpec: "",
      //                 skuName: "",
      //                 skuCode: ""
      //               });
      //               if (d.value) {
      //                 console.log("obj", obj);

      //                 form.val("storageWorkAddForm", {
      //                   ...obj,
      //                   warehouseInventoryTypeId: obj.inventoryType,
      //                   restQuantity: obj.hasSignQuantity - obj.hasStorageWorkQuantity,
      //                   quantity: obj.hasSignQuantity - obj.hasStorageWorkQuantity
      //                 });
      //                 setLocationTable();
      //               }
      //             },
      //             "skuName"
      //           );
      //         }
      //       },
      //       "signNo"
      //     );
      //   }
      // }
    );

    await admin.initDataSelectPro(
      "enterprisecab/warehouse/admin/warehouse/list",
      {
        limit: 999,
        status: 0
      },
      "warehouseId",
      "入库仓库",
      (d, obj) => {
        form.val("storageWorkAddForm", {
          warehouseTypeId: obj.warehouseTypeId,
          workbinStatus: obj.workbinStatus
        });
        setLocationTable();
      }
    );
    $("#purchaseSignForCodeBox").click(function () {
      let inventoryTypeCode = form.val("storageWorkAddForm").inventoryTypeCode;
      if (!inventoryTypeCode) {
        layer.msg("请选择入库类型");
        return false;
      }

      admin.formOpen({
        area: ["90%", "85%"],
        title: "添加入库签收单",
        path: "components/purchase/purchaseSignFor.html",
        success: function () {
          parentData.eventName = "radio";
          parentData.where = {
            inventoryTypeCode: inventoryTypeCode,
            workType: "doWork"
          };
        },
        end: function () {
          let obj = {};
          form.val("storageWorkAddForm", {
            logisticsNo: "",
            waybillNo: "",
            inTypeName: "",
            externalCode: "",
            supplierName: "",
            supplierCode: ""
          });
          if (childData.list && childData.list.length > 0) {
            obj = childData.list[0];
            console.log(obj);
            
            form.val("storageWorkAddForm", {
              logisticsNo: obj.logisticsNo,
              waybillNo: obj.waybillNo,
              inTypeName: obj.inventoryTypeName,
              externalCode: obj.sn,
              supplierName: obj.supplierName,
              supplierCode: obj.supplierCode,
              supplierId: obj.supplierId,
              purchaseSignForId: obj.id,
              signNo: obj.signNo
            });
            getSkuInfo(obj.id);
          }
        }
      });
    });

    async function getSkuInfo(id) {
      await admin.initDataSelectPro(
        "enterprise/purchase/admin/purchaseSignForProduct/list",
        {
          limit: 999,
          purchaseSignForId: id
        },
        "purchaseSignForProductId",
        "入库签收产品",
        async (d, obj) => {
          form.val("storageWorkAddForm", {
            ...obj,
            warehouseInventoryTypeId: "",
            restQuantity: "",
            quantity: "",
            skuSpec: "",
            skuName: "",
            skuCode: ""

          });
          if (d.value) {
            form.val("storageWorkAddForm", {
              ...obj,
              warehouseInventoryTypeId: obj.inventoryType,
              restQuantity: obj.hasSignQuantity - obj.hasStorageWorkQuantity,
              quantity: obj.hasSignQuantity - obj.hasStorageWorkQuantity
            });
            setLocationTable();
          }
        },
        "skuName"
      );
    }

    async function setLocationTable() {
      table.reload("locationTable", {
        where: {
          productDetailId: $("#productDetailId").val() ? $("#productDetailId").val() : "-1",
          warehouseId: $("#warehouseId").val() ? $("#warehouseId").val() : "-1"
        }
      });
      // console.log($("#productDetailId").val());
      // console.log($("#warehouseId").val());
      // insTb.reload({where: data.field,page: {curr: 1}},'data');

      // \table.reload("locationTable", {
      //   data: []
      // });
      // let productDetailId = $("#productDetailId").val();
      // let warehouseId = $("#warehouseId").val();
      // if (productDetailId && warehouseId) {
      //   const res = await admin.reqPro("enterprise/storage/admin/productInventoryDetail/list", {
      //     productDetailId,
      //     warehouseId
      //   });
      //   const warehouseAreaRes = await admin.reqPro("enterprisecab/warehouse/admin/warehouseArea/list", {
      //     limit: 999,
      //     warehouseId
      //   });
      //   table.reload("locationTable", {
      //     data: [
      //       ...res.data,
      //       {
      //         warehouseShelfSpaceId: "",
      //         warehouseShelfSpaceList: [],
      //         palletBoxId: "",
      //         palletBoxList: [],
      //         quantity: 0,
      //         warehouseShelfId: "",
      //         warehouseShelfList: [],
      //         warehouseAreaId: "",
      //         warehouseAreaList: warehouseAreaRes.data,
      //         operate: "",
      //         tyep: "新增"
      //       }
      //     ]
      //   });
      // }
    }

    // 监听price输入
    $("#price").on("input", function () {
      let price = $(this).val() || 0;
      let quantity = $("#quantity").val() || 0;
      let totalPrice = (price * quantity).toFixed(6);
      $("#totalPrice").val(totalPrice);
    });
    // 监听quantity输入
    $("#quantity").on("input", function () {
      let price = $("#price").val() || 0;
      let quantity = $(this).val() || 0;
      let totalPrice = (price * quantity).toFixed(6);
      $("#totalPrice").val(totalPrice);
    });

    table.on("radio(locationTable)", function (obj) {
      var data = obj.data; //获取选中的数据
      console.log(data);
    });
    // 提交
    form.on("submit(purchaseStorageWorkFormAddSubmit)", function (obj) {
      const formData = { ...obj.field, ...form.val("storageWorkAddForm") };
      formData.palletBoxId = Number(formData.palletBoxId);
      // console.log(form.val('storageWorkAddForm'));

      console.log(formData);
      // return ;
      // if (nowData.eventName === "add") {
      if (formData.quantity <= 0) {
        layer.msg("入库数量不能小于0");
        return false;
      }
      if (formData.quantity - formData.restQuantity > 0) {
        layer.msg("入库数量不能大于待入库数量");
        return false;
      }
      formData.purchaseStorageWorkProduct = {
        ...table.checkStatus("locationTable").data[0],
        ...obj.field
      };
      // } else {
      //   let checkObj = table.checkStatus("locationTable").data[0];
      //   formData.warehouseAreaId = checkObj.warehouseAreaId;
      //   formData.warehouseShelfId = checkObj.warehouseShelfId;
      //   formData.warehouseShelfSpaceId = checkObj.warehouseShelfSpaceId;
      //   formData.palletBoxId = checkObj.palletBoxId;
      // }
      // if (table.checkStatus("locationTable").data.length == 0) {
      //   layer.msg("请选择入库位置");
      //   return false;
      // }

      console.log(formData);
      if (nowData.eventName == "add") {
        admin.req(
          "enterprise/purchase/admin/purchaseStorageWork/add",
          JSON.stringify(formData),
          function (res) {
            layer.closeAll("loading");
            if (res.code == 200) {
              layer.msg(res.msg, {
                icon: 1
              });
              table.reload("purchaseStorageWorkTable");
              layer.closeAll("page");
            } else {
              layer.msg(res.msg, {
                icon: 2
              });
            }
          },
          "POST",
          false,
          "application/json"
        );
      } else if (nowData.eventName == "simpleAdd") {
        admin.req(
          "enterprise/purchase/admin/purchaseStorageWork/simpleStorage",
          JSON.stringify(formData),
          function (res) {
            layer.closeAll("loading");
            console.log(nowData);

            if (res.code == 200) {
              layer.msg(res.msg, {
                icon: 1
              });
              table.reload("purchaseStorageWorkTable");
              layer.closeAll("page");
            }
          },
          "POST",
          false,
          "application/json"
        );
      }

      return false;
    });
  });
</script>
<style>
  /* #locationTable .layui-table-body, .layui-table-box, .layui-table-cell {
    overflow: visible !important;
  } */
  /* #locationTable .layui-table-body,
#locationTable .layui-table-box,
#locationTable .layui-table-cell {
    overflow: visible !important;
} */
</style>
